limsMaterialApply.auditPage = function(pageType) {

    return {
        getGridParam: function () {
            var _this = this
            return {
                type: 'grid',
                id: _this.idManager.materialApplyGrid,
                url: _this.urlManager.materialApplyGrid + '/queries/tasks',
                requestData: {
                    bpmn_statusCode: pageType
                },
                columns: limsMaterialApply.getAuditListColumns(),
                onCellClick: function (field, row) {
                    field === 'applyCode' && _this.loadDetailPage(row);
                },
                onLoadSuccess: function (data) {
                    if (!Gikam.isEmpty(data)) {
                        this.activeRowByIndex(0)
                    } else {
                    }
                },
                onRowActive: function (index, row) {
                },
                page: true,
                toolbar: [{
                    type: 'button',
                    text: pageType === 'audit'?'GIKAM.WORKFLOW.BUTTON.PASS':'T_LIMS_MATERIAL_APPLY.OUT_SUCCESS',
                    icon: 'pass',
                    onClick: function () {
                        _this.pass()
                    }
                }, {
                    type: 'button',
                    text: 'GIKAM.WORKFLOW.BUTTON.REJECT',
                    icon: 'reject',
                    hidden: pageType !== 'audit',
                    onClick: function () {
                        _this.reject()
                    }
                }]
            }
        },

        loadDetailPage: function (row, readonly) {
            workspace.window.load(limsMaterialApply.baseUrl + '/page/edit-detail' + Gikam.param({
                id: row.id,
                step: pageType,
            }))
        },

        idManager: {
            materialApplyGrid: 'lims-material-apply-audit-list-grid-'+pageType,
        },

        urlManager: {
            materialApplyGrid: limsMaterialApply.baseUrl,
        },

        pass: function () {
            let _this = this
            var grid = Gikam.getComp(_this.idManager.materialApplyGrid);
            Gikam.create('workflow').pass({
                data: grid.getSelections(),
                pageObject: limsMaterialApply,
                formatterToolbar: (toolbar, type, formId) => {
                    toolbar.forEach(b => {
                        if (b.text === 'GIKAM.BUTTON.CONFIRM') {
                            b.class = 'blue'
                            b.icon = 'save'
                            b.color = 'white'
                        } else if (b.text === 'GIKAM.BUTTON.CANCEL') {
                            b.icon = 'back'
                        }
                    })
                    return toolbar
                }
            }).done(function () {
                grid.refresh()
            })
        },

        reject: function () {
            let _this = this
            var grid = Gikam.getComp(_this.idManager.materialApplyGrid)
            Gikam.create('workflow').reject({
                data: grid.getSelections(),
                pageObject: limsMaterialApply,
                formatterToolbar: (toolbar, type, formId) => {
                    toolbar.forEach(b => {
                        if (b.text === 'GIKAM.BUTTON.CONFIRM') {
                            b.class = 'blue'
                            b.icon = 'save'
                            b.color = 'white'
                        } else if (b.text === 'GIKAM.BUTTON.CANCEL') {
                            b.icon = 'back'
                        }
                    })
                    return toolbar
                }
            }).done(function () {
                grid.refresh()
            })
        },

        create: function () {
            var _this = this;
            Gikam.create('layout', {
                id: 'lims-material-apply-audit-list-layout',
                renderTo: workspace.window.$dom,
                center: {
                    items: [this.getGridParam()]
                }
            })
        },

        init: function (param) {
            this.param = param
            this.create()
        }
    }
}
